package com.zecan.springcloud.service.impl;

import com.zecan.springcloud.service.StreamProviderServer;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.MessageChannel;

import javax.annotation.Resource;
import java.util.UUID;

/**
 * @ClassName StreamProviderServerImPL
 * @Description TODO
 * @date 2022/5/10 9:54
 * @Version 1.0
 */
@EnableBinding(value = Source.class)
public class StreamProviderServerImpl implements StreamProviderServer {

    @Resource
    private MessageChannel output;

    @Value(value = "${server.port}")
    private String serverPort;


    @Override
    public String send() {
        String msg = UUID.randomUUID().toString();
        output.send(MessageBuilder.withPayload(msg).build());
        System.out.println("*******serial: " + msg + "\t" +serverPort);
        return null;
    }
}
